package app.view.mediators
{
	import app.AppConstants;
	import app.model.proxies.FlareDataProxy;
	import app.view.component.FSMVisualisation;
	
	import flare.vis.data.Data;
	import flare.vis.events.SelectionEvent;
	
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;

	public class FSMVisualisationMediator extends Mediator
	{
		public static const NAME:String = "FSMVisualisationMediator"
		public function FSMVisualisationMediator(viewComponent:Object=null)
		{
			super(NAME, viewComponent);
		}
		
		override public function onRegister():void{
			view.addEventListener(SelectionEvent.DESELECT, onDeselect);
			view.addEventListener(SelectionEvent.SELECT, onSelect);
		}
		
		private function onDeselect( event:SelectionEvent ):void{
			sendNotification(AppConstants.NODE_ROLL_OUT, event.node );
		}
		
		private function onSelect( event:SelectionEvent ):void{
			sendNotification(AppConstants.NODE_ROLL_OVER, event.node );
		}
		
		override public function listNotificationInterests():Array{
			return [	FlareDataProxy.FLARE_DATA_POPULATED,
						FlareDataProxy.DATA_FLUSHED
															]
		}
		
		override public function handleNotification(note:INotification):void{
			
			switch( note.getName() ){
				
				case FlareDataProxy.FLARE_DATA_POPULATED:
					view.dataProvider = Data( note.getBody() );
					break;
					
				case FlareDataProxy.DATA_FLUSHED:
					view.flush();
					break;
					
			
				
			}
		}
		
		private function get view():FSMVisualisation{
			return FSMVisualisation(viewComponent);
		}
		
	}
}